<template>
  <div>
    <list
      ref="list"
      :disabled="!$permission.canRead()"
    >
      <template #toolbar-left>
        <el-button
          @click="importOldIcpCustomerTitleToNewIcp"
          type="primary"
          :loading="importLoading"
          :disabled="!$permission.canWrite()"
        >导入到新系统</el-button>
      </template>
      <!-- <template #column>
        <el-table-column
          label="操作"
          fixed="right"
          align="center"
          width="80"
          v-if="$permission.canWrite()"
        >
          <template slot-scope="{row}">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="edit(row)"
              :disabled="row.id<0"
            />
            <el-button
              size="mini"
              type="text"
              icon="el-icon-delete"
              @click="del(row)"
              :disabled="row.id<0"
            />
          </template>
        </el-table-column>
      </template> -->
    </list>
  </div>
</template>

<script>
import list from "@/components/crm/customerTitle/oldIcpList";
import curdMixins from "@/mixins/curd";
import api from "@/api/crm/customerTitle";
export default {
  components: {
    list
  },
  mixins: [curdMixins],
  data() {
    return {
      importLoading:false,
      syncEsLoading: false,
      syncIcpLoading: false,
      resetLoading: false,
    };
  },
  created() { },
  methods: {
    importOldIcpCustomerTitleToNewIcp() {
      var rows = this.$refs.list.getCheckedRows();
      let message = "确定要将选中的抬头导入到新系统吗？";
      let postData;
      if (rows && rows.length > 0) {
        postData = { ids: rows.map((item) => item.id) };
      } else {
        message = "确定要将抬头列表查询结果导入新系统吗？"
        postData = this.$refs.list.$refs.list.tempQueryParams;
      }
      this.$confirm(message, "提示", {
        type: "warning",
      })
        .then(() => {
          this.importLoading = true;
          console.log(postData);
          api.importOldIcpCustomerTitleToNewIcp(postData).then((res) => {
            this.importLoading = false;
          });
        })
        .catch((e) => { 
          console.log(e)
        });
    }
  },
};
</script>